<!--
    amusement 文件夹下主要存放 “休闲娱乐” 相关的 API
    优美句子
    内容展示：
        自定义列表组
        https://v4.bootcss.com/docs/components/list-group/#custom-content
-->
<template>
  <div class="container">

    <!--  面包屑导航 -->
    <nav aria-label="breadcrumb">
      <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="/onlinetool/#/">首页</a></li>
        <li class="breadcrumb-item"><a href="#">休闲娱乐</a></li>
        <li class="breadcrumb-item active" aria-current="page">优美句子</li>
      </ol>
    </nav>

    <!--  头部卡片  -->
    <div class="card border-primary">
      <!--  放在 .card 里面的标签默认宽度会占满父元素宽度, 所以 a 标签应该放在 .card-body 里面-->
      <div class="card-header bg-info font-weight-bold">优美句子</div>
      <div class="card-body ">
        <h5 class="card-title text-primary">来一些优美的句子吧~</h5>
        <p class="card-text"></p>
        <!--          <a href="#" class="btn btn-outline-success">获取每日笑话</a>-->
        <button type="button" @click="getSentence" class="btn btn-outline-success">获取句子</button>

        <div class="spinner-border text-success ml-5" role="status">
          <span class="sr-only">Loading...</span>
        </div>
      </div>
    </div>

    <!--  内容展示区域  -->
    <div class="list-group mt-3 ">
      <div v-on:click.prevent  v-for="item in sentence" :key="item.id" class="list-group-item list-group-item-action  align-items-start border">
        <div class="d-flex w-100 justify-content-between">
          <h5 class="mb-1 text-info">{{ "《" + item.title + "》"}}</h5>
        </div>
        <p class="mb-1">{{ item.digest }}</p>
        <small>{{ "-----  " +  item.author}}</small>
      </div>
    </div>

  </div>
</template>

<script>
  export default {
    name: 'BeautifulSentence',
    data() {
      return {
        sentence: {},
      }
    },
    methods: {
      async getSentence() {
        this.$(".spinner-border").css("display", "inline-block");

        const result = await this.$http.get('https://api.berryapi.net',{
          params: {
            service: "App.Article.Rand",
            app_key: "GuEE5IUSVUhQrSG0"
          }
        });
        this.sentence = result.data;

        if (this.sentence !== null) {
          this.$(".spinner-border").css("display", "none");
        }


      }
    }

  }
</script>

<style scoped>

  .spinner-border {
    display: none;
  }

  .list-group div:nth-child(1) {
    display: none;
  }

  .list-group div:nth-child(3) {
    display: none;
  }

</style>
